package com.sky.controller.user;

import com.sky.context.BaseContext;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "C端购电清单相关接口")
public class ShopCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    @PostMapping("/add")
    @ApiOperation("添加购电清单")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购电清单商品信息为：{}",shoppingCartDTO);
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation("查看购电清单")
    public Result<List<ShoppingCart>> list(){
        Long userId = BaseContext.getCurrentId();
        List<ShoppingCart> list=shoppingCartService.getByUserId(userId);
        log.info("购电清单的内容为：{}",list);
        return Result.success(list);
    }
    @DeleteMapping("/clean")
    @ApiOperation("清空购电清单")
    public Result clean(){
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
    @PostMapping("/sub")
    @ApiOperation("删除购点清单的一个商品")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.deleteOne(shoppingCartDTO);
        return Result.success();
    }
}
